package com.app.buss.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.app.buss.R;
import com.app.buss.bean.NewsBean;
import com.app.buss.bean.TopBean;
import com.app.buss.ui.ForwebActivity;
import com.bumptech.glide.Glide;

import java.util.List;

public class TopAdapter extends RecyclerView.Adapter<TopAdapter.MViewHolder> {
    private List<TopBean> datas;
    private Context context;

    public TopAdapter(List<TopBean> datas, Context context){
     this.datas = datas;
     this.context = context;
    }

    @NonNull
    @Override
    public MViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_top, parent, false);
        return new MViewHolder(v);
    }

    @Override
    public void onBindViewHolder(@NonNull MViewHolder holder, int position) {
        Glide.with(context).load(datas.get(position).getPic()).into(holder.cover);
        holder.title.setText(position+1+"");
        holder.des.setText(datas.get(position).getMax());
        holder.num.setText(datas.get(position).getMin());
        holder.pairs.setText(datas.get(position).getPairs());
    }

    @Override
    public int getItemCount() {
        return datas.size();
    }

    static class MViewHolder extends RecyclerView.ViewHolder{
        ImageView cover;
        TextView title;
        TextView des;
        TextView num;
        TextView pairs;

        MViewHolder(@NonNull View itemView) {
            super(itemView);
            cover = itemView.findViewById(R.id.img_icon);
            title = itemView.findViewById(R.id.tv_rank);
            des = itemView.findViewById(R.id.tv_max);
            num = itemView.findViewById(R.id.tv_min);
            pairs = itemView.findViewById(R.id.tv_pairs);

        }
    }
}
